import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
import router from './router';
import { store, key } from './store';
import { createPinia } from 'pinia';
import 'element-plus/dist/index.css';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import zhLang from 'element-plus/lib/locale/lang/zh-cn';
zhLang.el.pagination.goto = '跳转';
import QcSelect from '@/components/qcSelect/index.vue';
import btnAntiShake from '@/utils/btnAntiShake'
import config from '@/utils/config'


const pinia = createPinia();

const app = createApp(App);

app.config.globalProperties.$config = config;

app.use(pinia);
app.use(router);

app.use(store, key);

app.use(btnAntiShake);

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.component('qc-select', QcSelect);

// app.mount('#app');


document.title = `${config.name}${config.title}`;

// 腾讯地图加载
if (import.meta.env.VITE_ENV_MAP === 'tx') {
  (window as any).init = () => {
    app.mount('#app');
  }
  //异步加载地图库函数文件
  const loadScript = () => {
    //创建script标签
    var script = document.createElement('script');
    //设置标签的type属性
    script.type = 'text/javascript';
    //设置标签的链接地址
    script.src = `https://map.qq.com/api/js?v=2.exp&key=${import.meta.env.VITE_ENV_KEY}&callback=init`;
    //添加标签到dom
    document.body.appendChild(script);
  }
  window.onload = loadScript;
} else {
  app.mount('#app');
}

// 立地替换浏览器页签图标
if (import.meta.env.VITE_ENV_TYPE === 'ld') {
  // 删除rel为icon的link标签，解决link一直增加导致favicon不能即时刷新的问题
  document.head.querySelectorAll("link").forEach(link => {
    if (link.rel === 'icon') {
      link.parentNode?.removeChild(link);
    }
  })
  // 修改浏览器页签图标
  const link = document.createElement('link');
  link.rel = "icon";
  link.href = '/src/assets/icon-ld.png'
  document.head.append(link);
}